# -*- coding: utf-8 -*-
"""
Created on Fri Oct 11 23:06:08 2019

@author: vistor
"""

import PySimpleGUI as sg
from urllib import request
import re
import time

layout = [[sg.Text('请输入要翻译的句子：'),sg.InputText()],
           [sg.Button("翻译")],
           #[sg.Text("翻译结果为：")]
           ]##[sg.Output()]

window = sg.Window("Pytranslator -0.1.1",layout)
event, values = window.read()
sous=values[0].replace(' ','')
sr = "http://translate.google.cn/translate_a/\
single?client=gtx&sl=en&tl=zh-CN&dt=t&q="+sous
resp = request.urlopen(sr)
li = resp.read().decode()
pat = re.compile(r'[\u4e00-\u9fa5]+')
ans = pat.findall(li)
sg.Popup("翻译结果",ans)
time.sleep(5)
window.close()
